package pzl.com.customannotation;

import android.util.Log;

import pzl.com.customannotation.annotations.Anno1;
import pzl.com.customannotation.annotations.Anno2;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-11]
 */
public class InheritedTest {
    static String TAG = "InheritedTest";

    public static void main(String[] args) {
        //f2(Child2.class);
        //f1(Child1.class);

        Class<Child2> c2 = Child2.class;
        if (c2.isAnnotationPresent(Anno2.class)) {
            Anno2 annotation = c2.getAnnotation(Anno2.class);
            String value1 = annotation.work();
            boolean value2 = annotation.isInherited();
            System.out.println(" Child2 work=" + value1);
            System.out.println(" Child2 Inherited=" + value2);
        }

        Class<Child1> c1 = Child1.class;
        if (c1.isAnnotationPresent(Anno1.class)) {
            Anno1 annotation = c1.getAnnotation(Anno1.class);
            String value1 = annotation.work();
            boolean value2 = annotation.isInherited();
            System.out.println("Child1 work=" + value1);
            System.out.println("Child1 Inherited=" + value2);
        }

    }

    static void f2(Class c) {
        Anno2 anno2 = (Anno2) c.getAnnotation(Anno2.class);
        if (anno2 != null) {
            Log.e(TAG, "isInherited:" + anno2.isInherited() + " work:" + anno2.work());
        }
        Log.e(TAG, "anno2:" + anno2);
    }

    static void f1(Class c) {
        Anno1 anno1 = (Anno1) c.getAnnotation(Anno1.class);
        if (anno1 != null) {
            Log.e(TAG, "isInherited:" + anno1.isInherited() + " work:" + anno1.work());
        }
        Log.e(TAG, "anno1:" + anno1);
    }

}
